/*
 * @Author: ChunLai
 * @Date: 2022-06-15 15:03:30
 * @LastEditTime: 2025-11-20 15:05:34
 * @Description: 续保
 * @FilePath: \01.latest-short-insure\src\store\modules\renewal.js
 */

const state = {
  riskBase: [],
  prePlanNowCode: "",
  initRiskFirst: 0,
  contExpiryDate:"",//新单终保日期
};
const getters = {
  prePlanNowCode: (state) => state.prePlanNowCode,
  contExpiryDate: (state) => state.contExpiryDate,
};
const mutations = {
  SET_STATE_FIELD(state, payload) {
    Object.assign(state, payload);
  },
  SET_RISK_BASE(state, payload) {
    state.riskBase = payload;
  },
  SET_EXPIRY_DATE(state, payload) {
    state.contExpiryDate = payload;
  },
};
const actions = {
  initPreRisk({ state, dispatch, rootState, commit }, risks) {
    return new Promise((reslove, reject) => {
      commit("SET_RISK_BASE", risks);
      if (state.initRiskFirst == 1) return;
      dispatch("readings/initFilesList", {}, { root: true });
      dispatch("json/getBaseDataJson", "notice", { root: true });
      const mrisk = risks[0],
        preCode = mrisk.planCode,
        planArr = rootState.risks[0].plansArr;
      const planItem = planArr.find((e) => e.preCode == preCode);
      if (planItem) {
        dispatch(
          "risks/setRisks",
          {
            varietyCode: rootState.risks[0].varietyCode,
            type: "planCode",
            val: planItem.value,
          },
          { root: true }
        );
        state.prePlanNowCode = planItem.value;
        state.initRiskFirst = 1;
      }
    });
  },
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
